package com.ihighest.app.infox.adapter;

import org.json.JSONArray;
import org.json.JSONException;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ihighest.app.common.kit.AppKit;
import com.ihighest.app.infox.R;

public class MyQuestionAndAnswerAdapter extends BaseAdapter {
	JSONArray array;
	Activity activity;
	LayoutInflater inflater = null;

	// protected ImageLoader imageLoader = ImageLoader.getInstance();
	// DisplayImageOptions options;

	public MyQuestionAndAnswerAdapter(Activity activity, JSONArray array) {
		this.activity = activity;
		this.array = array;
		inflater = LayoutInflater.from(activity);

	}

	public MyQuestionAndAnswerAdapter(Activity activity) {
		this.activity = activity;
		inflater = LayoutInflater.from(activity);

	}

	@Override
	public int getCount() {
		return array == null ? 0 : array.length();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.infox_activity_myquestion_list_item, null);
			holder.itemMassage = (TextView) convertView.findViewById(R.id.itemMassage);
			holder.itemUserImg = (ImageView) convertView.findViewById(R.id.itemUserImg);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		String url = "";
		try {
			url = array.getJSONObject(position).getString("img");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		// DisplayImageOptions defaultOptions = new
		// DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.infox_person_no_icon)
		// .showImageOnFail(R.drawable.infox_person_no_icon).showImageOnLoading(R.drawable.infox_person_no_icon).cacheInMemory(true)
		// .cacheOnDisc(true).build();
		// ImageLoader.getInstance().displayImage(url, holder.itemUserImg,
		// defaultOptions);
		AppKit.SetUserImg(url, holder.itemUserImg);
		// holder.itemMassage.setTextSize(SharedPreferencesKit.getFloat(activity,
		// Const.SP_TEXTSIZE, Const.noramlSize));
		return convertView;
	}

	static class ViewHolder {

		TextView itemMassage;
		ImageView itemUserImg;

	}

}
